//
//  OrderHeadView.m
//  YiBaoStore
//
//  Created by 吕清毅 on 2018/10/21.
//  Copyright © 2018年 小河. All rights reserved.
//

#import "OrderHeadView.h"

@implementation OrderHeadView

- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithReuseIdentifier:reuseIdentifier];
    if (self) {
        //self.backgroundColor = TotalWhite;
        [self setView];
    }
    return self;
}

- (void)setView
{
    if (!self.lineView) {
        self.lineView = [UILabel new];
        self.lineView.backgroundColor = UIColorFromHex(0xF7F7F7);
        [self addSubview:self.lineView];
    }
    
    if (!self.orderCodeLab) {
        self.orderCodeLab = [UILabel new];
        self.orderCodeLab.textColor = UIColorFromHex(0x999999);
        self.orderCodeLab.font = FontWithSize(13);
        self.orderCodeLab.attributedText = [TTKUtil getAtttributeStringWithLineSpace:0 kern:-0.8 and:@"订单号：2087234839458"];
        [self addSubview:self.orderCodeLab];
    }
    if (!self.statueLab) {
        self.statueLab = [UILabel new];
        self.statueLab.textColor = goldColor;
        self.statueLab.font = FontWithSize(14);
        self.statueLab.text = @"已发货";
        self.statueLab.textAlignment = NSTextAlignmentRight;
        [self addSubview:self.statueLab];
    }
    if (!self.timeLab) {
        self.timeLab = [UILabel new];
        self.timeLab.textColor = UIColorFromHex(0x999999);
        self.timeLab.font = FontWithSize(12);
        self.timeLab.attributedText = [TTKUtil getAtttributeStringWithLineSpace:0 kern:-0.6 and:@"2018-08-25 16:39:30"];
        [self addSubview:self.timeLab];
    }
    if (!self.pickLab) {
        self.pickLab = [UILabel new];
        self.pickLab.textColor = UIColorFromHex(0x999999);
        self.pickLab.font = FontWithSize(12);
        self.pickLab.attributedText = [TTKUtil getAtttributeStringWithLineSpace:0 kern:-1 and:@"取件码：1234"];
        self.pickLab.textAlignment = NSTextAlignmentRight;
        [self addSubview:self.pickLab];
    }
    if (!self.midLine) {
        self.midLine = [UIView new];
        self.midLine.backgroundColor = UIColorFromHex(0xF7F7F7);
        [self addSubview:self.midLine];
    }
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    self.lineView.frame = CGRectMake(0, 0, self.width, 10);
    self.orderCodeLab.frame = CGRectMake(15, 20, self.width-15-80, 16);
    self.statueLab.frame = CGRectMake(self.width-150, 21, 130, 14);
    self.timeLab.frame = CGRectMake(self.orderCodeLab.left, self.orderCodeLab.bottom+10, 135, 12);
    self.pickLab.frame = CGRectMake(self.width-100, self.statueLab.bottom+11, 85, 12);
    self.midLine.frame = CGRectMake(0, self.timeLab.bottom+10, self.width, 1);
}

- (void)getData:(OrderModel *)model
{
    self.model = model;
    self.orderCodeLab.text = [NSString stringWithFormat:@"订单号：%ld",(long)model.id];
    self.statueLab.text = [NSString stringWithFormat:@"%@",model.orderStateDesc];
    if ([model.orderStateDesc isEqualToString:@"已冻结"]) {
        self.pickLab.hidden = YES;
    }
    if (model.type == 2 || model.type== 3) {
        if (![TTKUtil isNil:model.deliveryId])
        {
            self.pickLab.hidden = NO;
            self.pickLab.text = model.type == 2?[NSString stringWithFormat:@"取件码:%@",model.deliveryId]:@"扫码支付";
        }
        else
        {
            self.pickLab.hidden = YES;
        }
    }
    else
    {
         self.pickLab.hidden = YES;
    }
    self.timeLab.text = [NSString stringWithFormat:@"%@",model.gmtCreate];
}

@end
